package com.zkyc.framework.algorithm.controller;

import com.alibaba.fastjson.JSONObject;
import com.zkyc.framework.algorithm.service.SegmentationService;
import com.zkyc.framework.algorithm.service.SenstiveWordService;
import com.zkyc.framework.common.exception.ResultCode;
import com.zkyc.framework.common.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("word")
public class AlgorithmController {


    @Autowired
    private SegmentationService segmentationService;

    @Autowired
    private SenstiveWordService senstiveWordService;

    private String CORRECTURL="";

    /**
     * 中文纠错算法
     *
     * @return
     */
    @PostMapping("/chineseCorrect")
    public ResultVO<?> chineseCorrect(@RequestBody String para) {
        return segmentationService.chineseCorrect(para);
    }

    /**
     * 中文分词算法 （用于搜索引擎）
     *
     * @return
     */
    @PostMapping("/chineseSegment")
    public ResultVO<?> chineseSegment(@RequestBody String para) {
        List<String> textList = segmentationService.chineseSegment(JSONObject.parseObject(para).getString("text"));
        return ResultVO.data(textList);
    }

    /**
     * 敏感词匹配算法
     *
     * @return
     */
    @PostMapping("/senstiveWordCheck")
    public ResultVO<?> senstiveWordCheck(@RequestBody String para) {
        Set<String> sensitiveWordSet = senstiveWordService.senstiveWordCheck(JSONObject.parseObject(para).getString("text"));
        return ResultVO.data(sensitiveWordSet);
    }

    /**
     * 敏感词匹配算法
     *
     * @return
     */
    @GetMapping("/senstiveWordRefresh")
    public ResultVO<?> senstiveWordRefresh() {
        senstiveWordService.senstiveWordRefresh();
        return ResultVO.success(ResultCode.SUCCESS);
    }
}
